﻿using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System;
using BF.Membership.MembershipEF;

namespace BF.Membership.Common
{
    /// <summary>
    /// 公共类库
    /// </summary>
    public partial class PubSysCommon
    {
        #region 字段

        private static WSJD_aspnetdbEntities DBEntities;

        #endregion

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        static PubSysCommon()
        {

        }
        #endregion

        #region 属性

        /// <summary>
        /// 获取关键字
        /// </summary>
        public string GetKey
        {
            get
            {

                return GetDataBase.ExecuteScalar(CommandType.StoredProcedure, "GetKey").ToString();
            }
        }

        #endregion

        #region 静态方法

        /// <summary>
        /// 获取ADO.NET操作所需的DataBase对象
        /// </summary>
        public static Database GetDataBase
        {
            get
            {
                return DatabaseFactory.CreateDatabase();
            }
        }

        /// <summary>
        /// 获取ADO.NET Entity对象
        /// </summary>
        public static WSJD_aspnetdbEntities GetDBEntities
        {
            get
            {
                DBEntities = new WSJD_aspnetdbEntities();
                return DBEntities;
            }
        }

        /// <summary>
        /// 释放ADO.NET Entity对象
        /// </summary>
        public static void DisposeDBEntities()
        {
            DBEntities.Dispose();
        }
        #endregion

        ///// <summary>
        ///// 获得随机编码
        ///// </summary>
        ///// <returns></returns>
        //public static string RandomCode()
        //{
        //    return new Random(DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond).Next().ToString().Substring(2, 5);
        //}
    }
}